package com.ruoyi.community.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.community.domain.Visit;
import com.ruoyi.community.service.IVisitService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 访客Controller
 * 
 * @author lj
 * @date 2022-02-22
 */
@RestController
@RequestMapping("/community/visit")
public class VisitController extends BaseController
{
    @Autowired
    private IVisitService visitService;

    /**
     * 查询访客列表
     */
    @PreAuthorize("@ss.hasPermi('community:visit:list')")
    @GetMapping("/list")
    public TableDataInfo list(Visit visit)
    {
        startPage();
        List<Visit> list = visitService.selectVisitList(visit);
        return getDataTable(list);
    }

    /**
     * 导出访客列表
     */
    @PreAuthorize("@ss.hasPermi('community:visit:export')")
    @Log(title = "访客", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, Visit visit)
    {
        List<Visit> list = visitService.selectVisitList(visit);
        ExcelUtil<Visit> util = new ExcelUtil<Visit>(Visit.class);
        util.exportExcel(response, list, "访客数据");
    }

    /**
     * 获取访客详细信息
     */
    @PreAuthorize("@ss.hasPermi('community:visit:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(visitService.selectVisitById(id));
    }

    /**
     * 新增访客
     */
    @PreAuthorize("@ss.hasPermi('community:visit:add')")
    @Log(title = "访客", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Visit visit)
    {
        return toAjax(visitService.insertVisit(visit));
    }

    /**
     * 修改访客
     */
    @PreAuthorize("@ss.hasPermi('community:visit:edit')")
    @Log(title = "访客", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Visit visit)
    {
        return toAjax(visitService.updateVisit(visit));
    }

    /**
     * 删除访客
     */
    @PreAuthorize("@ss.hasPermi('community:visit:remove')")
    @Log(title = "访客", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(visitService.updateVisitByIds(ids));
    }
}
